package com.yaozheng.vocationaltraining.service.impl;

import java.util.HashMap;

import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.EBean;

import net.sf.json.JSONObject;

import com.yaozheng.vocationaltraining.iview.BaseView;
import com.yaozheng.vocationaltraining.iview.IBaseView;
import com.yaozheng.vocationaltraining.iview.IOnlineExamView;
import com.yaozheng.vocationaltraining.service.OnlineExamService;
import com.yaozheng.vocationaltraining.utils.Constants;
import com.yaozheng.vocationaltraining.utils.ErrorUtils;
import com.yaozheng.vocationaltraining.utils.http.okhttp.OkHttpClientManager;

/**
 * 闯关
 *
 * @author Administrator
 */
@EBean
public class OnlineCheckpointsExamServiceImpl implements
        OnlineExamService {

    IOnlineExamView iOnlineExamView;

    public void init(IOnlineExamView iOnlineExamView) {
        this.iOnlineExamView = iOnlineExamView;
    }

    @Override
    public void getQuestionList(int paperId) {
    }

    @Background
    @Override
    public void submitAnswers(int paperId, String answers) {
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("id", paperId);
            jsonObject.put("answers", answers);
            OkHttpClientManager.getInstance().postJson(
                    Constants.ROOTURL + "/exam/master",
                    iOnlineExamView.getToken(), jsonObject.toString(),
                    new OkHttpClientManager.IBaseViewCallback(new BaseView(iOnlineExamView) {

                        @Override
                        public void responseSuccess(JSONObject jsonObject) {
                            iOnlineExamView.submitAnswersSuccess(jsonObject);
                        }

                        @Override
                        public void responseError(String error) {
                            iOnlineExamView.submitAnswersError(error);
                        }

                    }));
        } catch (Exception e) {
            ErrorUtils.outErrorLog(e);
            if (iOnlineExamView.isResponseResult()) {
                iOnlineExamView
                        .submitAnswersError(ErrorUtils.SERVER_CONNECTION_ERROR);
            }

        }
    }

    @Override
    public void loadSaiKuangInfo(int gameId) {

    }


}
